$OpenBSD: patch-src_unexelf_c,v 1.3 2016/06/28 14:06:59 kettenis Exp $
--- src/unexelf.c.orig	Tue Oct 15 16:21:44 2002
+++ src/unexelf.c	Mon Jun 27 23:19:45 2016
@@ -460,7 +460,7 @@ extern void fatal (char *, ...);
 #define MAP_FAILED ((void *) -1)
 #endif
 
-#if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
+#if defined (__alpha__) && !defined (__NetBSD__)
 /* Declare COFF debugging symbol table.  This used to be in
    /usr/include/sym.h, but this file is no longer included in Red Hat
    5.0 and presumably in any other glibc 2.x based distribution.  */
@@ -549,10 +549,12 @@ typedef struct {
 # else
 #  define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type
 # endif
-# ifdef _LP64
-#  define ELFSIZE 64
-# else
-#  define ELFSIZE 32
+# ifndef __OpenBSD__
+#  ifdef _LP64
+#   define ELFSIZE 64
+#  else
+#   define ELFSIZE 32
+#  endif
 # endif
   /* This macro expands `bits' before invoking ElfBitsW.  */
 # define ElfExpandBitsW(bits, type) ElfBitsW (bits, type)
@@ -753,10 +755,12 @@ unexec (new_name, old_name, data_start, bss_start, ent
   old_bss_index = find_section (".bss", old_section_names,
 				old_name, old_file_h, old_section_h, 0);
 
+#ifndef __powerpc__
   old_sbss_index = find_section (".sbss", old_section_names,
 				 old_name, old_file_h, old_section_h, 1);
   if (old_sbss_index != -1)
     if (OLD_SECTION_H (old_sbss_index).sh_type == SHT_PROGBITS)
+#endif
       old_sbss_index = -1;
 
   if (old_sbss_index == -1)
@@ -786,8 +790,16 @@ unexec (new_name, old_name, data_start, bss_start, ent
 #endif
   new_data2_addr = old_bss_addr;
   new_data2_size = new_bss_addr - old_bss_addr;
+#if defined (__hppa__) || defined (__powerpc__)
+  new_data2_offset  = OLD_SECTION_H (old_bss_index).sh_offset +
+    (new_data2_addr - OLD_SECTION_H (old_bss_index).sh_addr);
+  new_data2_offset =
+    round_up (new_data2_offset,
+	      OLD_SECTION_H (old_bss_index).sh_addralign);
+#else
   new_data2_offset  = OLD_SECTION_H (old_data_index).sh_offset +
     (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr);
+#endif
 
 #ifdef DEBUG
   fprintf (stderr, "old_bss_index %d\n", old_bss_index);
@@ -891,6 +903,9 @@ unexec (new_name, old_name, data_start, bss_start, ent
 
   /* Make sure that the size includes any padding before the old .bss
      section.  */
+#if defined (__hppa__) || defined (__powerpc__)
+  NEW_PROGRAM_H (n).p_offset = new_data2_offset;
+#endif
   NEW_PROGRAM_H (n).p_filesz = new_bss_addr - NEW_PROGRAM_H (n).p_vaddr;
   NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz;
 
